import { createDirAndWriteFile, deleteFolder } from "../fs";
import path from "path";
import { $context } from "@ap/extension";
import * as vscode from "vscode";

export async function createTempFile(
  content: string,
  filePath: string,
): Promise<vscode.Uri> {
  const tempDir = getTempFolder();
  const tempFilePath = path.join(tempDir, filePath);
  await createDirAndWriteFile(tempFilePath, content);
  return vscode.Uri.file(tempFilePath);
}

export async function delTempFolder(): Promise<void> {
  const tempDir = getTempFolder();
  return await deleteFolder(tempDir);
}

function getTempFolder(): string {
  return path.join($context.extensionPath, "temp");
}
